package java041;
import java.util.Arrays;
import java.util.Scanner;

class PersonSortable implements Comparable<PersonSortable>{
	private String name;
	private int age;
	public PersonSortable(String name,int age){
		this.name=name;
		this.age=age;
	}
	
	public String getName() {
		return name;
	}

	
	public int getAge() {
		return age;
	}

	

	@Override
	public String toString() {
		return name+"-"+age;
	}
	@Override
	public int compareTo(PersonSortable o) {
		int x=this.name.compareTo(o.name);
		if(x!=0)
			return x;
		return this.getAge()-o.getAge(); 
					
	}
	
	
}
public class Java0401 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		PersonSortable[] ps=new PersonSortable[n];
		for(int i=0;i<n;i++){
			ps[i]=new PersonSortable(in.next(),in.nextInt());
		}
		Arrays.sort(ps);
		for(PersonSortable p:ps)
			System.out.println(p);
		System.out.println(Arrays.toString(PersonSortable.class.getInterfaces()));

	}

}
